package com.hclc.config.aop.joblog;


import com.hclc.config.context.AppContext;
import com.hclc.config.util.AssertUtil;
import com.hclc.entity.model.JobLogsModel;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: hef
 * 任务日志收集工具
 * @Date: Create in 9:06 上午 2020/11/9
 */
public class JobLogUtil {

    /**
     * 任务日志缓存key
     */
    public static final String JOB_LOG_KEY = "jobLogKey";

    /**
     * 保存日志
     *
     * @param messagePattern
     * @param argArray
     * @return void
     * @Description: TODO(保存日志)
     * @author hef
     * @version 1.0
     * @date 2020/11/9 1:35 下午
     */
    public static void saveLog(final String messagePattern, final Object... argArray) {
        List<JobLogsModel> jobLogsModels = (ArrayList<JobLogsModel>) AppContext.getThreadContext(JOB_LOG_KEY);
        AssertUtil.isTrue(jobLogsModels != null, "日志缓存对象不能为空");

        JobLogsModel jobLogsModel = new JobLogsModel();
        jobLogsModel.setContent(MessageFormatter.format(messagePattern, argArray));
        jobLogsModel.setLogDatetime(LocalDateTime.now());
//        jobLogsModel.setJobRecordId();
//        jobLogsModel.setJobId();
        jobLogsModels.add(jobLogsModel);
    }

}
